package main

import (
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	uuid "github.com/satori/go.uuid"
	"time"
)

func main() {
	fmt.Println(genXWSSE())
}

// genXWSSE 生成xwsse
func genXWSSE() string {
	xwsse := `UsernameToken Username="bacbbf530e6e4ca3af5577b6c17b158c", PasswordDigest="%s", Nonce="%s", Created="%s"`
	nonce := genNonce()
	created := time.Now().Format("2006-01-02T15:04:05Z")
	password := "3836fb915b41d22a929cb182dba2dba5838b13362c08509b563497d5a0777c88"
	tmp := sha256.Sum256([]byte(nonce + created + password))
	passwordDigest := tmp[:]
	return fmt.Sprintf(xwsse, base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(passwordDigest))), nonce, created)
}

// genNonce 生成nonce
func genNonce() string {
	return uuid.NewV4().String()
}
